#include<bits/stdc++.h>
#define int long long

using namespace std;

int m;

signed main() {
	cin >> m;
	int a[1010];
	int cnt = 0;
	
	int t = 10;
	
	while(m > 0) {
	 	while(m - pow(3, t) >= 0 ) {
	 		m -= pow(3, t);
	 		a[++cnt] = t;
		 }		
		 t -- ;
	}
	cout << cnt << endl;
	for(int i = 1; i <= cnt; i ++ ) {
		cout << a[i] << " ";
	}
	return 0;
}

